package com.xindaoapp.henghua.db.model;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteStatement;

import com.xindaoapp.henghua.db.DaoSession;
import com.xindaoapp.henghua.entry.SuperVisionInfo;

import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import de.greenrobot.dao.internal.DaoConfig;

/**
 * 设备信息
 * @author chenghao
 *
 */
public class SupervisionDao extends AbstractDao<SuperVisionInfo, String> {
	public static final String TABLENAME = "supervision";

	public SupervisionDao(DaoConfig config) {
		super(config);
	}

	public SupervisionDao(DaoConfig config, DaoSession daoSession) {
		super(config, daoSession);
	}

	/**
	 * Properties of entity Note.<br/>
	 * Can be used for QueryBuilder and for referencing column names.
	 */
	public static class Properties {
		public final static Property Id = new Property(0, String.class, "id", false, "id");
		public final static Property AssertId = new Property(1, String.class, "assert_id", false,
				"assert_id", false);
		public final static Property Notes = new Property(2, String.class, "notes", false, "notes", false);
	};

	/** Creates the underlying database table. */
	public static void createTable(SQLiteDatabase db, boolean ifNotExists) {
		String constraint = ifNotExists ? "IF NOT EXISTS " : "";
		db.execSQL(String.format("CREATE TABLE %s '%s' (%s, %s, %s);", constraint, TABLENAME,
				createSqlCreate(Properties.Id), createSqlCreate(Properties.AssertId),
				createSqlCreate(Properties.Notes)));
	}

	/** Drops the underlying database table. */
	public static void dropTable(SQLiteDatabase db, boolean ifExists) {
		String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "'" + TABLENAME + "'";
		db.execSQL(sql);
	}

	@Override
	protected SuperVisionInfo readEntity(Cursor cursor, int offset) {
//		SuperVisionInfo entity = new SuperVisionInfo(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0),
//				cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
		SuperVisionInfo entity = new SuperVisionInfo();
		entity.id = cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
		entity.assert_id = cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1);
		entity.notes = cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
		return entity;
	}

	@Override
	protected String readKey(Cursor cursor, int offset) {
//		return cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
		return null;
	}

	@Override
	protected void readEntity(Cursor cursor, SuperVisionInfo entity, int offset) {
		entity.id = cursor.isNull(offset + 0) ? null : cursor.getString(offset + 0);
		entity.assert_id = cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1);
		entity.notes = cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2);
	}

	@Override
	protected void bindValues(SQLiteStatement stmt, SuperVisionInfo entity) {
		stmt.clearBindings();

		stmt.bindString(1, entity.id);
		stmt.bindString(2, entity.assert_id);
		stmt.bindString(3, entity.notes);
	}

	@Override
	protected String updateKeyAfterInsert(SuperVisionInfo entity, long rowId) {
		return entity.id;
	}

	@Override
	protected String getKey(SuperVisionInfo entity) {
		if (entity != null) {
			return entity.id;
		} else {
			return null;
		}
	}

	@Override
	protected boolean isEntityUpdateable() {
		return true;
	}

}
